<extend name="./base" />

<block name="body">
<link rel="stylesheet" href="/Public/admin/css/sb-admin-pop.css">
    <table class="table">
      <caption>家长列表</caption>
      <thead>
        <tr>
          <th>电话号码</th>
          <th>姓名</th>
          <th>身份证号码</th>
          <th>地址</th>
          <th>审核</th>
          <th>注册时间</th>
          <th>修改</th>
        </tr>
      </thead>
      <tbody>
      <?php  if($data){?>
      <foreach name="data" item="vo">
        <tr>
          <td <if condition="($vo.status eq 0) ">style="color:yellow;"</if>>{$vo.phone}</td>
          <td class="user_name">{$vo.name}</td>
          <td class="user_cardnum">{$vo.cardnum}</td>
          <td class="user_address">{$vo.address}</td>
          <td>
              <select class="cl_status" data-id="{$vo.new_user_id}" >
                  <option value="0" <if condition="($vo.status eq 0) "> selected  </if> >待审核</option>
                  <option value="1" <if condition="($vo.status eq 1) "> selected  </if>>已审核</option>
                  <option value="2" <if condition="($vo.status eq 2) "> selected  </if>>审核失败</option>
              </select>
          </td>
          <td>
              {$vo.addtime}
          </td>
          <td><a href="javascript:;" class="modify">修改</a>
        <input type="hidden" value="{$vo.new_user_id}"  class="user_id">
          </td>

        </tr>
     </foreach>   
     <?php }else{?>   
     <tr><td>暂无数据</td></tr>
      <?php }?>
      </tbody>
    </table>
    <div>
        {$render}
    </div>
    
    <div class="modal fade" id="modifyPanel" tabindex="-1" role="dialog" aria-labelledby="FastFindModalLabel" aria-hidden="true">
        <div class="modal-dialog text-center">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modifyPanel" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="FastFindModalLabel">修改家长信息</h4>
                </div>
                <form action="#" id="modifyForm" method="post">
                    <div class="form-group clearfix">
                        <label class="control-label left" for="new_name">姓名</label>
                        <input class="form-control login-field new_name" type="text" placeholder="请输入姓名" id="new_name" name="new_name" required="">
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label left" for="new_cardnum">身份证号码</label>
                        <input class="form-control login-field new_cardnum" type="text" placeholder="请输入身份证号码" id="new_cardnum" name="new_cardnum" required="">
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label left" for="new_address">地址</label>
                        <input class="form-control login-field new_address" type="text" placeholder="请输入地址" id="new_address" name="new_address" required="">
                    </div>
                    <a href="javascript:;" class="btn btn-lg btn-block modify_click  " data-dismiss="modal" type="submit">确认修改</a>
                </form>
            </div>
        </div>
    </div>
     <script type="text/javascript">
   $(".cl_certified").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        var this_type = 1;
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Parent/verify",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    is_certified:this_status,
                    type:this_type
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');                      
                    } else{
                        alert('操作失败!');   
                    }
                }
            })
        }else{
            location.reload();
        };
    });
</script>

     <script type="text/javascript">
   $(".cl_status").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        var this_type = 2;
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Parent/verify",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    status:this_status,
                    type:this_type
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');                      
                    } else{
                        alert('操作失败!');   
                    }
                }
            })
        }else{
            location.reload();
        };
    });
</script>


     <script type="text/javascript">
   $(".is_star").change(function(){
        var this_id = $(this).data("id");
        var this_status=$(this).val();
        alert(this_status);
        if ( confirm('你确定操作吗？') ) {
            $.ajax({
                type: "post",
                url: "__ROOT__/index.php/Admin/Teacher/star",
                dataType: 'json',
                data:{
                    user_id:this_id,
                    star:this_status,
                },
                success: function(result) {
                    if ( result.flag == 1) {
                        alert('操作成功!');                      
                    } else{
                        alert('操作失败!');   
                    }
                }
            })
        }
    });
   var $user_id;
   var $user_name;
   var $user_cardnum;
   var $user_address;
   //点击修改
   $('.modify').on('click',function(){
       $user_name=$(this).parent().siblings('.user_name').text();
       $user_cardnum=$(this).parent().siblings('.user_cardnum').text();
       $user_address=$(this).parent().siblings('.user_address').text();
       $user_id=$(this).next('.user_id').val();
       $('.new_name').val($user_name);
       $('.new_cardnum').val($user_cardnum);
       $('.new_address').val($user_address);

    $('#modifyPanel').show().addClass('in');
   });

   // 提交修改
  $('#complainBtn').click(function() {
    var str = $('#complainForm').serialize();

    $.ajax({
      url: '/Home/Order/complain',
      type: 'post',
      dataType: 'json',
      data: str
    })
    .done(function(res) {
      if (res.error) {
        alert(res.msg);
        return;
      }
      $('.modal-header .close').trigger('click');
    });
  });

    $(' .close').click(function() {
    $('#'+$(this).attr('data-dismiss')).hide().removeClass('in');
  });
   // 提交修改
    $('.modify_click').click(function(){

        var name =  $('#new_name').val();
        var cardnum =  $('#new_cardnum').val();
        var address =  $('#new_address').val();
        
        if (!/^[\u4e00-\u9fa5]{2,4}$/.test(name)){
            alert('请填写要修改的姓名');
            return false;
        }
        if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(cardnum)){
            alert('请填写要修改的身份证号');
            return false;
        }
        if(!/^[\u4e00-\u9fa5]+$/.test(address)){
            alert('请填写要修改的地址');
            return false;
        }
        $.ajax({
            type:"post",
            url:"/Admin/Parent/changeinfo",
            dataType:"json",
            data:{
                name:name,
                cardnum:cardnum,
                address:address,
                user_id:$user_id,
            },
            success: function(data) {
                        if ( data.error == 1) {
                            alert('操作失败!');
                         } else{
                             $('#modifyPanel').hide().removeClass('in');
                             location.reload();
                         }            }
        });
    })
</script>
</block>